import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
// 配置@别名
import * as path from "path";
// 写法一
// export default defineConfig({
//   plugins: [vue()],
//   resolve: {
//     extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
//     alias: {
//       "@": path.resolve(__dirname, "./src"),
//       $Style: path.resolve("src/assets/scss"),
//       $Api: path.resolve("src/api"),
//       $Components: path.resolve("src/components"),
//       $Img: path.resolve("src/assets/img"),
//       $Uitls: path.resolve("src/utils"),
//       $Router: path.resolve("src/router"),
//       $Views: path.resolve("src/views"),
//     },
//   },
//   server: {
//     host: true,
//     cors: true,
//     port: 8080,
//   },
// });
// 写法二
export default ({ command, mode }) => {
  console.log(
    `环境变量：${mode}，后台地址：${loadEnv(mode, process.cwd()).VITE_BASE_URL}`
  );
  return defineConfig({
    plugins: [vue()],
    resolve: {
      extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
      alias: {
        "@": path.resolve(__dirname, "./src"),
        $Style: path.resolve("src/assets/scss"),
        $Api: path.resolve("src/api"),
        $Components: path.resolve("src/components"),
        $Img: path.resolve("src/assets/img"),
        $Uitls: path.resolve("src/utils"),
        $Router: path.resolve("src/router"),
        $Views: path.resolve("src/views"),
      },
    },
    envPrefix: ["VUE_APP_", "VITE_"],
    server: {
      host: true,
      cors: true,
      port: 8080,
    },
  });
};
